package Computer;

/**
 * PCB class.
 * 
 * @author Stephen Amos, Zach Turk, Dickson Kwong
 *
 */

public class PCB {
	
	private int my_pid;
	
	private State my_state;
	
	private WaitingOn my_waiting_on;
	
	private int my_owns_semaphore;

	public PCB(int the_id, int the_owns_semaphore) {
		my_pid = the_id;
		my_state = PCB.State.READY;
		my_waiting_on = PCB.WaitingOn.NONE;
		my_owns_semaphore = the_owns_semaphore;
	}
	
	/**
	 * Get the PCB ID.
	 * @author Zac
	 * @return The PCB ID.
	 */
	public int getPID() {
		return my_pid;
	}
	
	/**
	 * Get the PCB state.
	 * @author Dickson Kwong
	 * @return The PCB state.
	 */
	public State getState() {
		return my_state;
	}
	
	/**
	 * Set the new PCB state.
	 * @author Dickson Kwong
	 * @param the_state The new PCB state.
	 */
	public void setWaitingOn(WaitingOn the_waiting_on)
	{
		my_waiting_on = the_waiting_on;
	}
	
	/**
	 * Set the new PCB state.
	 * @author Dickson Kwong
	 * @param the_state The new PCB state.
	 */
	public void setState(State the_state)
	{
		my_state = the_state;
	}

	/**
	 * Get which queue is PCB in if PCB is waiting 
	 * on something (blocked).
	 * @author Dickson Kwong
	 * @return which queue is PCB in.
	 */
	public WaitingOn getWaitingOn() {
		return my_waiting_on;
	}

	/**
	 * Get which semaphore does the PCB own.
	 * @author Dickson Kwong
	 * @return which semaphore does the PCB own.
	 */
	public int getOwnsSemaphore() {
		return my_owns_semaphore;
	}

	/**
	 * An enum class for the which queue the PCB in.
	 * @author Dickson Kwong
	 */
	public enum WaitingOn {
		 NONE, CPU, DISK, VIDEO, SEM;
		public String toString() {
			String s = super.toString();
			return s.substring(0, 1) + s.substring(1).toLowerCase();
		}
	}
	
	/**
	 * An enum class for the PCB state.
	 * @author Dickson Kwong
	 */
	public enum State {
		 RUNNING, READY, INTERRUPTED, BLOCKED, FINISHED, OWNER;
		public String toString() {
			String s = super.toString();
			return s.substring(0, 1) + s.substring(1).toLowerCase();
		}
	}
	
	
	
}